﻿// See https://aka.ms/new-console-template for more information
using System;
using System.Collections.Generic;

// Abstract base class for shapes
abstract class Shape
{
    public abstract double CalculateArea();
}

// Concrete class for Rectangle
class Rectangle : Shape
{
    private double Length { get; }
    private double Width { get; }

    public Rectangle(double length, double width)
    {
        Length = length;
        Width = width;
    }

    public override double CalculateArea()
    {
        return Length * Width;
    }

    public override string ToString()
    {
        return $"Rectangle (Length: {Length}, Width: {Width})";
    }
}

// Concrete class for Circle
class Circle : Shape
{
    private double Radius { get; }

    public Circle(double radius)
    {
        Radius = radius;
    }

    public override double CalculateArea()
    {
        return Math.PI * Radius * Radius;
    }

    public override string ToString()
    {
        return $"Circle (Radius: {Radius})";
    }
}

// Simple factory for creating shapes
class ShapeFactory
{
    public Shape CreateShape(string shapeType, double[] parameters)
    {
        switch (shapeType.ToLower())
        {
            case "rectangle":
                if (parameters.Length != 2)
                    throw new ArgumentException("Rectangle requires 2 parameters: length and width");
                return new Rectangle(parameters[0], parameters[1]);

            case "circle":
                if (parameters.Length != 1)
                    throw new ArgumentException("Circle requires 1 parameter: radius");
                return new Circle(parameters[0]);

            default:
                throw new ArgumentException("Invalid shape type");
        }
    }
}

class Program
{
    static void Main()
    {
        var random = new Random(); // 创建随机数生成器对象
        var shapeFactory = new ShapeFactory(); 
        var shapes = new List<Shape>(); 

        for (int i = 0; i < 10; i++)
        {
            string[] shapeTypes = { "rectangle", "circle" }; 
            string randomShapeType = shapeTypes[random.Next(shapeTypes.Length)]; // 随机选择一个形状类型

            double[] parameters; 

            if (randomShapeType == "rectangle")
                parameters = new double[] { random.Next(1, 10), random.Next(1, 10) };
            else
                parameters = new double[] { random.Next(1, 10) }; 

            
            Shape shape = shapeFactory.CreateShape(randomShapeType, parameters);
            shapes.Add(shape);
        }

        double totalArea = 0; 
        foreach (var shape in shapes)
        {
            
            Console.WriteLine($"形状: {shape}, 面积: {shape.CalculateArea():F2}");
            totalArea += shape.CalculateArea(); 
        }

        Console.WriteLine($"总面积: {totalArea:F2}");
    }
}
